package com.lucun.es_transaction.controller;

import com.lucun.es_transaction.config.RolePermission;
import com.lucun.es_transaction.entity.User;
import com.lucun.es_transaction.service.UserService;
import com.lucun.es_transaction.util.AuthorityUtil;
import com.lucun.es_transaction.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService service;

    /**
     * 用户注册
     */
    @RolePermission(login = false)
    @RequestMapping("/insertSelective")
    public JsonResult<?> insertSelective(@RequestBody User user) {
        return service.insertSelective(user);
    }

    @RolePermission(login = false)
    @RequestMapping("/selectAll")
    public List<User> selectAll() {
        return service.selectAll();
    }

    /**
     * 用户修改
     */
    @RolePermission(role = AuthorityUtil.FIRST)
    @RequestMapping("/updateByPrimaryKeySelective")
    public JsonResult<?> updateByPrimaryKeySelective(@RequestBody User user, HttpServletRequest request) {
        return service.updateByPrimaryKeySelective(user, request);
    }

    /**
     * 用户注销
     */
    @RequestMapping("/delete")
    @RolePermission(role = AuthorityUtil.THIRD)
    public JsonResult<?> delete(HttpServletRequest request) {
        return service.delete(request);
    }

    /**
     * 获取验证码
     */
    @RolePermission(login = false)
    @RequestMapping("/insertCode")
    public JsonResult<?> insertCode(@RequestBody User user) {
        return service.insertCode(user);
    }

    /**
     * 用户登录
     */
    @RolePermission(login = false)
    @RequestMapping("/login")
    public JsonResult<?> login(@RequestBody User user) {
        return service.login(user);
    }

    /*
    * 查询所有
    * */
    @RolePermission(login = false)
    @RequestMapping("/aa")
    public List<User> aa() {
        return service.selectAll();

    }
}
